package com.jason.www.activity;

import android.util.Log;
import android.view.View;

import com.jason.www.R;
import com.jason.www.base.BaseActivity;
import com.jason.www.widget.dialogfragment.ListDialogFragment;
import com.xiasuhuei321.loadingdialog.view.LoadingDialog;

import butterknife.OnClick;
import skin.support.SkinCompatManager;

public class ThirdLibraryActivity extends BaseActivity {
    private static final String TAG = "ThirdLibraryActivity";

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_third_library;
    }

    @OnClick({R.id.ll_loading_dialog, R.id.ll_pic_crop, R.id.ll_skin_change, R.id.ll_consecutiveScroller})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_loading_dialog:
                LoadingDialog loadingDialog = new LoadingDialog(mContext);
                loadingDialog.setLoadingText("加载中...");
                loadingDialog.setInterceptBack(false);
                loadingDialog.show();
                break;
            case R.id.ll_pic_crop:
                startActivity(ImageCropActivity.class);
                break;
            case R.id.ll_skin_change:
                changeSkin();
                break;
            case R.id.ll_consecutiveScroller:
                startActivity(ConsecutiveScrollerActivity.class);
                break;
        }
    }

    private void changeSkin() {
        ListDialogFragment fragment = new ListDialogFragment();
        fragment.setTitle("皮肤");
        fragment.setOnItemClickListener((position, str) -> {
            switch (position) {
                case 0:
                    //默认皮肤
                    SkinCompatManager.getInstance().restoreDefaultTheme();
                    break;
                case 1:
                    SkinCompatManager.getInstance().loadSkin("night", new SkinCompatManager.SkinLoaderListener() {
                        @Override
                        public void onStart() {
                            Log.d(TAG, "onStart: 换肤开始");
                        }

                        @Override
                        public void onSuccess() {
                            Log.d(TAG, "onSuccess: 换肤成功");
                        }

                        @Override
                        public void onFailed(String errMsg) {
                            Log.d(TAG, "onFailed: 换肤失败-->" + errMsg);
                        }
                    }, SkinCompatManager.SKIN_LOADER_STRATEGY_BUILD_IN);
                    break;
            }
        });
        fragment.updateList(new String[]{"默认皮肤", "暗黑模式"});
        fragment.show(this, "skin_change");
    }
}